home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / pgraf110.arc / DEMO_SUB.C < prev    next >
Text File  |  1991-06-21  |  27KB  |  875 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <fonts.h>
  5. #ifdef __TURBOC__
  6. #include <alloc.h>
  7. #endif
  8.  
  9. #define MAX_WIDTH 801            /* Maximum width of any PGRAPH viewport defined in the program */
  10.  
  11. extern int page_height, page_width;    /* Size of page in pixels */
  12. extern int prn;                            /* Output device */
  13.  
  14. void end_slice(void);
  15. #if defined(__HUGE__) || defined(__LARGE__) || defined(__MEDIUM__)
  16. void start_screen_output(void);
  17. void stop_screen_output(void);
  18.  
  19. static int screen_echo;
  20.  
  21. #ifdef __TURBOC__
  22. #include <graphics.h>
  23. #include <bgidrive.h>
  24. #define CLS cleardevice()
  25. #else
  26. #include <graph.h>
  27. #define CLS _clearscreen(0)
  28. #endif
  29. #endif
  30.  
  31. #include "pgraph.h"
  32.  
  33.  
  34. /********************************************************************
  35.  Draw lines, ellipses, polygons, move graphics cursor */
  36.  
  37. void shapes_demo(void)
  38. {
  39. int xasp, yasp;
  40. int xres, yres;
  41. int error_code;
  42. int width, height;
  43. long free_space;
  44. struct arccoordstype arccoords;
  45. static int polypoints[14] = {
  46.     500, 160,
  47.     500, 340,
  48.     450, 250,
  49.     400, 250,
  50.     350, 330,
  51.     360, 170,
  52.     500, 160};
  53.  
  54.     p_getresolution(&xres, &yres);
  55.     p_setviewport(0, 0, 0, 0, 1);
  56. #ifdef __TURBOC__
  57.     free_space = farcoreleft() - 0x4000L;       /* Leave room for other graph memory uses */
  58. #else
  59.     free_space = 409600L;                   /* Take 400K */
  60. #endif
  61.     width = (int)((long)xres * page_width / 100);
  62.     height = (int) (free_space * 8 / width);
  63.     height = min(height, (int)((long)yres * page_height / 100));
  64.     printf("Setting %d by %d pixel (%d*%d inches) viewport\n",
  65.         width, height, width/xres, height/yres);
  66.     p_setviewport(0, 0, width - 1, height - 1, 1);
  67.     error_code = p_graphresult();
  68.     if (error_code != grOk || height < 340) {
  69.         printf("Failed... Insufficient memory\n");
  70.         return;
  71.     }
  72.     p_setlinestyle(USERBIT_LINE, 0x8080, NORM_WIDTH);
  73.     printf("p_rectangle(0, 0, p_getmaxx(), p_getmaxy());\n");
  74.     p_rectangle(0, 0, p_getmaxx(), p_getmaxy());
  75.     p_setlinestyle(CENTER_LINE, 0, NORM_WIDTH);
  76.     printf("p_drawpoly(7, polypoints);\n");
  77.     p_drawpoly(7, polypoints);
  78.     printf("p_rectangle(220, 140, 270, 10);\n");
  79.     p_rectangle(220, 240, 270, 110);
  80.     printf("p_circle(p_getmaxx() - 120, 100, 100);\n");
  81.     p_circle(p_getmaxx() - 120, 100, 100);
  82.     printf("p_arc(p_getmaxx() - 220, 100, 45, 135, 100);\n");
  83.     p_arc(p_getmaxx() - 220, 100, 45, 135, 100);
  84.     p_getarccoords(&arccoords);
  85.     printf("Last arc centred at (%d, %d), from (%d, %d) to (%d, %d)\n",
  86.         arccoords.x, arccoords.y, arccoords.xstart, arccoords.ystart,
  87.         arccoords.xend, arccoords.yend);
  88.     printf("p_ellipse(90, 10, 0, 360, 30, 10);\n");
  89.     p_ellipse(90, 10, 0, 360, 30, 10);
  90.     printf("p_ellipse(160, 10, 0, 360, 5, 10);\n");
  91.     p_ellipse(160, 10, 0, 360, 5, 10);
  92.     printf("p_ellipse(200, 10, 45, 135, 30, 10);\n");
  93.     p_ellipse(200, 10, 45, 135, 30, 10);
  94.     printf("p_ellipse(240, 10, 45, 135, 5, 10);\n");
  95.     p_ellipse(240, 10, 45, 135, 5, 10);
  96.     printf("p_ellipse(280, 10, 45, 225, 30, 10);\n");
  97.     p_ellipse(280, 10, 45, 225, 30, 10);
  98.     printf("p_getaspectratio(&xasp, &yasp);\np_setaspectratio(xasp, yasp/3);\n");
  99.     p_getaspectratio(&xasp, &yasp);
  100.     p_setaspectratio(xasp, yasp/3);
  101.     printf("Same circle and arc as above, but Ycentre at 390\n");
  102.     p_circle(p_getmaxx() - 120, 390, 100);
  103.     p_arc(p_getmaxx() - 220, 390, 45, 135, 100);
  104.     printf("Width = %d, Height = %d\n", p_getmaxx(), p_getmaxy());
  105.     printf("Current position = (%d, %d)\n", p_getx(), p_gety());
  106.     printf("p_moveto(40, 50);\n");
  107.     p_moveto(40, 50);
  108.     printf("Current position = (%d, %d)\n", p_getx(), p_gety());
  109.     printf("p_moverel(+20, -10);\n");
  110.     p_moverel(+20, -10);
  111.     printf("Current position = (%d, %d)\n", p_getx(), p_gety());
  112.  
  113.     printf("Various ellipse fragments\n");
  114.     p_ellipse(450, 60,   0,  20, 100, 50);
  115.     p_ellipse(450, 60,  30,  60, 100, 50);
  116.     p_ellipse(450, 60,  70,  90, 100, 50);
  117.     p_ellipse(450, 60,  90, 110, 100, 50);
  118.     p_ellipse(450, 60, 120, 150, 100, 50);
  119.     p_ellipse(450, 60, 160, 180, 100, 50);
  120.     p_ellipse(450, 60, 180, 200, 100, 50);
  121.     p_ellipse(450, 60, 210, 240, 100, 50);
  122.     p_ellipse(450, 60, 250, 270, 100, 50);
  123.     p_ellipse(450, 60, 270, 290, 100, 50);
  124.     p_ellipse(450, 60, 300, 330, 100, 50);
  125.     p_ellipse(450, 60, 340, 360, 100, 50);
  126.     p_ellipse(100, 140, 20, 340, 100, 50);
  127.  
  128.     printf("Lines\n");
  129.     p_setlinestyle(DASHED_LINE, 0, NORM_WIDTH);
  130.     p_line(100, 140, 200, 140);
  131.     p_line(100, 140, 100, 90);
  132.     p_line(0, 200, 10, 250);
  133.     p_line(0, 200, 50, 210);
  134.     p_line(50, 210, 0, 220);
  135.     p_line(50, 210, 40, 250);
  136.     p_moveto(450, 60);
  137.     p_linerel(100, 0);
  138.     p_lineto(450, 110);
  139.  
  140.     printf("Pixels\n");
  141.     p_putpixel(319, 0, 1);
  142.     p_putpixel(319, 1, 1);
  143.     p_putpixel(319, 1, 0);
  144.     end_slice();
  145. }
  146.  
  147. /********************************************************************
  148.  Register stroked fonts, and print them in different sizes and
  149.  orientations */
  150.  
  151. void stroked_fonts_demo(void)
  152. {
  153. int goth_height, next_line;
  154.  
  155.     p_setviewport(0, 0, 719, 170, 1);
  156.     p_registerbgifont(gothic_font);
  157.     p_registerfarbgifont(script_font_far);
  158.     printf("Printing text size 1, horizontally\n");
  159.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 1);
  160.     p_outtextxy(0, 0, "Gothic 1");
  161.     goth_height = p_textheight("Gothic 1");
  162.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 1);
  163.     p_outtextxy(200, 0, "Script 1");
  164.     next_line = max(p_textheight("Script 1"), goth_height);
  165.  
  166.     printf("Printing text size 1, vertically\n");
  167.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 1);
  168.     p_outtextxy(360, 0, "Gothic 1");
  169.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 1);
  170.     p_outtextxy(380, 0, "Script 1");
  171.  
  172.     printf("Printing text size 2, horizontally\n");
  173.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 2);
  174.     p_outtextxy(0, next_line, "Gothic 2");
  175.     goth_height = p_textheight("Gothic 2");
  176.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 2);
  177.     p_outtextxy(200, next_line, "Script 2");
  178.     next_line += max(p_textheight("Script 2"), goth_height);
  179.  
  180.     printf("Printing text size 2, vertically\n");
  181.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 2);
  182.     p_outtextxy(410, 0, "Gothic 2");
  183.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 2);
  184.     p_outtextxy(430, 0, "Script 2");
  185.  
  186.     printf("Printing text size 3, horizontally\n");
  187.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 3);
  188.     p_outtextxy(0, next_line, "Gothic 3");
  189.     goth_height = p_textheight("Gothic 3");
  190.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 3);
  191.     p_outtextxy(200, next_line, "Script 3");
  192.     next_line += max(p_textheight("Script 3"), goth_height);
  193.  
  194.     printf("Printing text size 3, vertically\n");
  195.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 3);
  196.     p_outtextxy(465, 0, "Gothic 3");
  197.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 3);
  198.     p_outtextxy(500, 0, "Script 3");
  199.  
  200.     printf("Printing text size 4, horizontally\n");
  201.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 4);
  202.     p_outtextxy(0, next_line, "Gothic 4");
  203.     goth_height = p_textheight("Gothic 4");
  204.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 4);
  205.     p_outtextxy(200, next_line, "Script 4");
  206.     next_line += max(p_textheight("Script 4"), goth_height);
  207.  
  208.     printf("Printing text size 4, vertically\n");
  209.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 4);
  210.     p_outtextxy(540, 0, "Gothic 4");
  211.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 4);
  212.     p_outtextxy(580, 0, "Script 4");
  213.  
  214.     printf("Printing text size 5, horizontally\n");
  215.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 5);
  216.     p_outtextxy(0, next_line, "Gothic 5");
  217.     p_settextstyle(SCRIPT_FONT, HORIZ_DIR, 5);
  218.     p_outtextxy(200, next_line, "Script 5");
  219.  
  220.     printf("Printing text size 5, vertically\n");
  221.     p_settextstyle(GOTHIC_FONT, VERT_DIR, 5);
  222.     p_outtextxy(620, 0, "Gothic 5");
  223.     p_settextstyle(SCRIPT_FONT, VERT_DIR, 5);
  224.     p_outtextxy(660, 0, "Script 5");
  225.  
  226.     end_slice();
  227.  
  228.     p_setviewport(0, 0, 550, 240, 1);
  229.     printf("Printing text size 9, horizontally\n");
  230.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 9);
  231.     p_outtextxy(0, 0, "Gothic 9");
  232.     next_line = p_textheight("Gothic 9");
  233.  
  234.     printf("Printing text size 10, horizontally\n");
  235.     p_settextstyle(GOTHIC_FONT, HORIZ_DIR, 10);
  236.     p_outtextxy(0, next_line, "Gothic 10");
  237.  
  238.     end_slice();
  239. }
  240.  
  241. /********************************************************************
  242.  Print default font in various sizes and orientations */
  243. void default_font_demo(void)
  244. {
  245.     p_setviewport(0, 0, 680, 199, 1);
  246.     printf("Printing text size 1, horizontally\n");
  247.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  248.     p_outtextxy(0, 0, "Default 1");
  249.     printf("Printing text size 1, vertically\n");
  250.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 1);
  251.     p_outtextxy(360, 0, "Default 1");
  252.  
  253.     printf("Printing text size 2, horizontally\n");
  254.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
  255.     p_outtextxy(0, 18, "Default 2");
  256.     printf("Printing text size 2, vertically\n");
  257.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 2);
  258.     p_outtextxy(378, 0, "Default 2");
  259.  
  260.     printf("Printing text size 3, horizontally\n");
  261.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 3);
  262.     p_outtextxy(0, 40, "Default 3");
  263.     printf("Printing text size 3, vertically\n");
  264.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 3);
  265.     p_outtextxy(416, 0, "Default 3");
  266.  
  267.     printf("Printing text size 4, horizontally\n");
  268.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 4);
  269.     p_outtextxy(0, 65, "Default 4");
  270.     printf("Printing text size 4, vertically\n");
  271.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 4);
  272.     p_outtextxy(468, 0, "Default 4");
  273.  
  274.     printf("Printing text size 5, horizontally\n");
  275.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 5);
  276.     p_outtextxy(0, 100, "Default 5");
  277.     printf("Printing text size 5, vertically\n");
  278.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 5);
  279.     p_outtextxy(520, 0, "Default 5");
  280.  
  281.     printf("Printing text size 6, horizontally\n");
  282.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 6);
  283.     p_outtextxy(0, 150, "Default 6");
  284.     printf("Printing text size 6, vertically\n");
  285.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 6);
  286.     p_outtextxy(620, 0, "Default 6");
  287.  
  288.     end_slice();
  289.  
  290.     p_setviewport(0, 0, 800, 89, 1);
  291.     printf("Printing text size 10, horizontally\n");
  292.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 10);
  293.     p_outtextxy(0, 0, "Default 10");
  294.  
  295.     end_slice();
  296. }
  297.  
  298. /********************************************************************
  299.  Print stroked and default font horizontally, using various
  300.  justification settings */
  301.  
  302. void horiz_text_demo(void)
  303. {
  304. int i;
  305.     p_setviewport(0, 0, 760, 175, 1);
  306.     p_setlinestyle(DOTTED_LINE, 0, NORM_WIDTH);
  307.     for (i = 25; i <= 150; i += 25)
  308.         p_line(0,  i, p_getmaxx(),  i);
  309.     for (i = 100; i < p_getmaxx(); i += 100)
  310.         p_line( i, 0,  i, p_getmaxy());
  311.  
  312.     printf("Printing Triplex\n");
  313.     p_settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
  314.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  315.     p_outtextxy(100, 50, "Triplex left top");
  316.  
  317.     p_settextjustify(LEFT_TEXT, CENTER_TEXT);
  318.     p_outtextxy(300, 50, "Triplex left centre");
  319.  
  320.     p_settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  321.     p_outtextxy(500, 50, "Triplex left bottom");
  322.  
  323.     p_settextjustify(CENTER_TEXT, TOP_TEXT);
  324.     p_outtextxy(100, 100, "Triplex centre top");
  325.  
  326.     p_settextjustify(CENTER_TEXT, CENTER_TEXT);
  327.     p_outtextxy(300, 100, "Triplex centre centre");
  328.  
  329.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  330.     p_outtextxy(500, 100, "Triplex centre bottom");
  331.  
  332.     p_settextjustify(RIGHT_TEXT, TOP_TEXT);
  333.     p_outtextxy(100, 150, "Triplex right top");
  334.  
  335.     p_settextjustify(RIGHT_TEXT, CENTER_TEXT);
  336.     p_outtextxy(300, 150, "Triplex right centre");
  337.  
  338.     p_settextjustify(RIGHT_TEXT, BOTTOM_TEXT);
  339.     p_outtextxy(500, 150, "Triplex right bottom");
  340.  
  341.     printf("Printing Default\n");
  342.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  343.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  344.     p_outtextxy(200, 25, "Default left top");
  345.  
  346.     p_settextjustify(LEFT_TEXT, CENTER_TEXT);
  347.     p_outtextxy(400, 25, "Default left centre");
  348.  
  349.     p_settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  350.     p_outtextxy(600, 25, "Default left bottom");
  351.  
  352.     p_settextjustify(CENTER_TEXT, TOP_TEXT);
  353.     p_outtextxy(200, 75, "Default centre top");
  354.  
  355.     p_settextjustify(CENTER_TEXT, CENTER_TEXT);
  356.     p_outtextxy(400, 75, "Default centre centre");
  357.  
  358.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  359.     p_outtextxy(600, 75, "Default centre bottom");
  360.  
  361.     p_settextjustify(RIGHT_TEXT, TOP_TEXT);
  362.     p_outtextxy(200, 125, "Default right top");
  363.  
  364.     p_settextjustify(RIGHT_TEXT, CENTER_TEXT);
  365.     p_outtextxy(400, 125, "Default right centre");
  366.  
  367.     p_settextjustify(RIGHT_TEXT, BOTTOM_TEXT);
  368.     p_outtextxy(600, 125, "Default right bottom");
  369.  
  370.     end_slice();
  371. }
  372.  
  373. /********************************************************************
  374.  Print stroked and default font vertically, using various
  375.  justification settings */
  376.  
  377. void vert_text_demo(void)
  378. {
  379. int i;
  380.  
  381.     p_setviewport(0, 0, 642, 180, 1);
  382.     p_setlinestyle(DOTTED_LINE, 0, NORM_WIDTH);
  383.     for (i = 25; i <= 150; i += 25)
  384.         p_line(0,  i, p_getmaxx(),  i);
  385.     for (i = 20; i < p_getmaxx(); i += 20)
  386.         p_line( i, 0,  i, p_getmaxy());
  387.  
  388.     printf("Printing Triplex\n");
  389.     p_settextstyle(TRIPLEX_FONT, VERT_DIR, 1);
  390.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  391.     p_outtextxy(100, 50, "Triplex left top");
  392.  
  393.     p_settextjustify(LEFT_TEXT, CENTER_TEXT);
  394.     p_outtextxy(300, 50, "Triplex left centre");
  395.  
  396.     p_settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  397.     p_outtextxy(500, 50, "Triplex left bottom");
  398.  
  399.     p_settextjustify(CENTER_TEXT, TOP_TEXT);
  400.     p_outtextxy(120, 100, "Triplex centre top");
  401.  
  402.     p_settextjustify(CENTER_TEXT, CENTER_TEXT);
  403.     p_outtextxy(320, 100, "Triplex centre centre");
  404.  
  405.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  406.     p_outtextxy(520, 100, "Triplex centre bottom");
  407.  
  408.     p_settextjustify(RIGHT_TEXT, TOP_TEXT);
  409.     p_outtextxy(140, 150, "Triplex right top");
  410.  
  411.     p_settextjustify(RIGHT_TEXT, CENTER_TEXT);
  412.     p_outtextxy(340, 150, "Triplex right centre");
  413.  
  414.     p_settextjustify(RIGHT_TEXT, BOTTOM_TEXT);
  415.     p_outtextxy(540, 150, "Triplex right bottom");
  416.  
  417.     printf("Printing Default\n");
  418.     p_settextstyle(DEFAULT_FONT, VERT_DIR, 1);
  419.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  420.     p_outtextxy(200, 25, "Default left top");
  421.  
  422.     p_settextjustify(LEFT_TEXT, CENTER_TEXT);
  423.     p_outtextxy(400, 25, "Default left centre");
  424.  
  425.     p_settextjustify(LEFT_TEXT, BOTTOM_TEXT);
  426.     p_outtextxy(600, 25, "Default left bottom");
  427.  
  428.     p_settextjustify(CENTER_TEXT, TOP_TEXT);
  429.     p_outtextxy(220, 75, "Default centre top");
  430.  
  431.     p_settextjustify(CENTER_TEXT, CENTER_TEXT);
  432.     p_outtextxy(420, 75, "Default centre centre");
  433.  
  434.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  435.     p_outtextxy(620, 75, "Default centre bottom");
  436.  
  437.     p_settextjustify(RIGHT_TEXT, TOP_TEXT);
  438.     p_outtextxy(240, 125, "Default right top");
  439.  
  440.     p_settextjustify(RIGHT_TEXT, CENTER_TEXT);
  441.     p_outtextxy(440, 125, "Default right centre");
  442.  
  443.     p_settextjustify(RIGHT_TEXT, BOTTOM_TEXT);
  444.     p_outtextxy(640, 125, "Default right bottom");
  445.  
  446.     end_slice();
  447. }
  448.  
  449. /********************************************************************
  450.  Print stroked font, using various scaling factors */
  451.  
  452. void text_scaling_demo(void)
  453. {
  454. struct textsettingstype texttypeinfo;
  455. int lomode, himode;
  456.  
  457.     p_setviewport(0, 0, 660, 190, 1);
  458.     p_settextstyle(TRIPLEX_FONT, VERT_DIR, 1);
  459.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  460.  
  461.     p_gettextsettings(&texttypeinfo);
  462.     printf("Text set to font no. %d, direction = %s, size = %d\n",
  463.         texttypeinfo.font,
  464.         texttypeinfo.direction == HORIZ_DIR ? "Horizontal" : "Vertical",
  465.         texttypeinfo.charsize);
  466.     printf("Text justification is %s, %s\n",
  467.         texttypeinfo.horiz == LEFT_TEXT ? "Left" : texttypeinfo.horiz == CENTER_TEXT ? "Centre" : "Right",
  468.         texttypeinfo.vert  == TOP_TEXT  ? "Top"  : texttypeinfo.vert  == CENTER_TEXT ? "Centre" : "Bottom");
  469.  
  470.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
  471.     p_settextjustify(CENTER_TEXT, BOTTOM_TEXT);
  472.  
  473.     p_gettextsettings(&texttypeinfo);
  474.     printf("Text set to font no. %d, direction = %s, size = %d\n",
  475.         texttypeinfo.font,
  476.         texttypeinfo.direction == HORIZ_DIR ? "Horizontal" : "Vertical",
  477.         texttypeinfo.charsize);
  478.     printf("Text justification is %s, %s\n",
  479.         texttypeinfo.horiz == LEFT_TEXT ? "Left" : texttypeinfo.horiz == CENTER_TEXT ? "Centre" : "Right",
  480.         texttypeinfo.vert  == TOP_TEXT  ? "Top"  : texttypeinfo.vert  == CENTER_TEXT ? "Centre" : "Bottom");
  481.  
  482.     p_setusercharsize(3, 2, 1, 2);
  483.     p_settextstyle(TRIPLEX_FONT, HORIZ_DIR, 0);
  484.     p_settextjustify(LEFT_TEXT, TOP_TEXT);
  485.     p_outtextxy(0, 0, "Treble width, Normal height");
  486.     p_setusercharsize(1, 2, 1, 2);
  487.     p_outtextxy(0, 15, "Normal width, Normal height");
  488.     p_setusercharsize(1, 2, 3, 2);
  489.     p_outtextxy(0, 25, "Normal width, Treble height");
  490.     p_setusercharsize(3, 2, 3, 2);
  491.     p_outtextxy(0, 60, "Treble width, Treble height");
  492.     p_setusercharsize(1, 6, 1, 2);
  493.     p_outtextxy(0, 110, "1/3 width, Normal height");
  494.     p_setusercharsize(1, 2, 1, 6);
  495.     p_outtextxy(0, 140, "Normal width, 1/3 height");
  496.     p_setusercharsize(1, 6, 1, 6);
  497.     p_outtextxy(0, 170, "1/3 width, 1/3 height");
  498.  
  499.     p_settextstyle(TRIPLEX_FONT, HORIZ_DIR, 1);
  500.     printf("Width, height of 'ABC' in Triplex size  1 = %d, %d\n", p_textwidth("ABC"), p_textheight("ABC"));
  501.     p_settextstyle(TRIPLEX_FONT, HORIZ_DIR, 10);
  502.     printf("Width, height of 'ABC' in Triplex size 10 = %d, %d\n", p_textwidth("ABC"), p_textheight("ABC"));
  503.  
  504.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  505.     printf("Width, height of 'ABC' in Default size  1 = %d, %d\n", p_textwidth("ABC"), p_textheight("ABC"));
  506.     p_settextstyle(DEFAULT_FONT, HORIZ_DIR, 10);
  507.     printf("Width, height of 'ABC' in Default size 10 = %d, %d\n", p_textwidth("ABC"), p_textheight("ABC"));
  508.  
  509.     printf("Current graph mode    = %d\n", p_getgraphmode());
  510.     printf("Maximum graph mode    = %d\n", p_getmaxmode());
  511.     printf("Graph mode name       = %Fs\n", p_getmodename(p_getgraphmode()));
  512.     p_getmoderange(STAR, &lomode, &himode);
  513.     printf("Star NX-10 mode range = %d -- %d\n", lomode, himode);
  514.  
  515.     end_slice();
  516. }
  517.  
  518. /********************************************************************
  519.  Fill various shapes with various patterns */
  520.  
  521. void shape_fill_demo(void)
  522. {
  523. int i, xasp, yasp;
  524. static int polypoints[] = {
  525.     500, 10,
  526.     500, 190,
  527.     450, 100,
  528.     400, 100,
  529.     350, 180,
  530.     360, 20,
  531.     400, 20,
  532.     420, 70,
  533.     370, 100,
  534.     450, 20,
  535.     500, 10
  536.     };
  537. struct fillsettingstype fillinfo;
  538. static char user_pattern[8] =  "\xf0\x0f\xf0\x0f\xf0\x0f\xf0\x0f";
  539. char user_pattern2[8];
  540.  
  541.     printf("Printing in default viewport\n");
  542.     p_graphdefaults();
  543.     p_getaspectratio(&xasp, &yasp);
  544.     for (i = 0; i < 7; i++) {
  545.         p_setfillstyle(i, 1);
  546.         p_getfillsettings(&fillinfo);
  547.         printf("Fill style set to %d, colour %d\n", fillinfo.pattern, fillinfo.color);
  548.         p_fillellipse( i * 40 + 20, 20, 20, (int)(20L * xasp / yasp));
  549.     }
  550.  
  551.     p_setfillpattern(user_pattern, 1);
  552.     p_getfillpattern(user_pattern2);
  553.     p_getfillsettings(&fillinfo);
  554.     printf("Fill style set to %d, colour %d\n", fillinfo.pattern, fillinfo.color);
  555.     p_fillellipse( i * 40 + 20, 20, 20, (int)(20L * xasp / yasp));
  556.  
  557.     p_setfillstyle(LTSLASH_FILL, 1);
  558.     printf("p_fillpoly(11, polypoints);\n");
  559.     p_fillpoly(11, polypoints);
  560.  
  561.     printf("p_bar(370, 100, 500, 170)\n");
  562.     p_bar(570, 100, 600, 170);
  563.     printf("p_bar3d(0, 100, 50, 150, 25, 1)\n");
  564.     p_bar3d(0, 100, 50, 150, 25, 1);
  565.     printf("p_bar3d(70, 100, 120, 150, 25, 0)\n");
  566.     p_bar3d(70, 100, 120, 150, 25, 0);
  567.  
  568.     end_slice();
  569. }
  570.  
  571. /********************************************************************
  572.  Fill an arbitrary shape */
  573.  
  574. void flood_fill_demo(void)
  575. {
  576. static int polypoints[] = {
  577.     200, 10,
  578.     200, 190,
  579.     150, 100,
  580.     100, 100,
  581.      50, 180,
  582.      60, 20,
  583.     100, 20,
  584.     120, 70,
  585.      70, 100,
  586.     150, 20,
  587.     200, 10
  588.     };
  589.  
  590.     p_setviewport(0, 0, 719, 199, 1);
  591.     p_setcolor(1);
  592.     printf("Drawing polygon\n");
  593.     p_drawpoly(11, polypoints);
  594.     printf("Including a circle\n");
  595.     p_circle(150, 80, 10);
  596.     printf("Filling polygon\n");
  597.     p_floodfill(165, 80, 1);
  598.  
  599.     end_slice();
  600. }
  601.  
  602. /********************************************************************
  603.  Draw various lines in different directions, with a user-defined
  604.  pattern */
  605.  
  606. void lines_demo(void)
  607. {
  608. int i;
  609. struct linesettingstype linetypeinfo;
  610.  
  611.     p_setviewport(0, 0, 719, 199, 1);
  612.     p_setlinestyle(USERBIT_LINE, 0xfc02, THICK_WIDTH);
  613.     for (i = 0; i <= 100; i += 20) {
  614.         p_line(0, 0, 100, i);
  615.         p_line(319, 0, 200, i);
  616.         p_line(i, 199, 100, 100);
  617.         p_line(200, 199, 319-i, 100);
  618.     }
  619.     p_getlinesettings(&linetypeinfo);
  620.     printf("Current line settings: \n\tLine stype = %d\n\tUser pattern = %04x\n\
  621. \tThickness = %d\n\n", linetypeinfo.linestyle, linetypeinfo.upattern, linetypeinfo.thickness);
  622.  
  623.     end_slice();
  624. }
  625.  
  626. /********************************************************************
  627.  Draw an elliptical pie chart on the printer. */
  628.  
  629. static void draw_elliptical_pie(void)
  630. {
  631.     p_setviewport(0, 0, 500, 120, 1);
  632.     p_outtextxy(300, 50, "Elliptical Pie chart");
  633.     p_setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
  634.     p_setfillstyle(CLOSE_DOT_FILL, 1);
  635.     p_sector(150, 50, 0, 50, 75, 30);
  636.     p_setfillstyle(HATCH_FILL, 1);
  637.     p_sector(150, 50, 50, 120, 75, 30);
  638.     p_setfillstyle(XHATCH_FILL, 1);
  639.     p_sector(150, 50, 120, 190, 75, 30);
  640.     p_setfillstyle(WIDE_DOT_FILL, 1);
  641.     p_sector(150, 50, 190, 290, 75, 30);
  642.     p_setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
  643.     p_setfillstyle(INTERLEAVE_FILL, 1);
  644.     p_sector(160, 60, 290, 360, 75, 30);
  645. }
  646.  
  647. /********************************************************************
  648.  Draw a circular pie chart on the printer. */
  649.  
  650. void pie_demo(void)
  651. {
  652.     p_setviewport(0, 0, 500, 200, 1);
  653.     printf("Circular pie chart, various fill patterns\n");
  654.     p_outtextxy(300, 100, "Circular Pie chart");
  655.     printf("Slice 1, CLOSE DOT FILL.\n");
  656.     p_setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
  657.     p_setfillstyle(CLOSE_DOT_FILL, 1);
  658.     p_pieslice(150, 100, 0, 50, 75);
  659.     printf("Slice 2, HATCH FILL.\n");
  660.     p_setfillstyle(HATCH_FILL, 1);
  661.     p_pieslice(150, 100, 50, 120, 75);
  662.     printf("Slice 3, XHATCH FILL.\n");
  663.     p_setfillstyle(XHATCH_FILL, 1);
  664.     p_pieslice(150, 100, 120, 190, 75);
  665.     printf("Slice 4, WIDE DOT FILL.\n");
  666.     p_setfillstyle(WIDE_DOT_FILL, 1);
  667.     p_pieslice(150, 100, 190, 290, 75);
  668.     printf("Slice 5, INTERLEAVE FILL.\n");
  669.     p_setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
  670.     p_setfillstyle(INTERLEAVE_FILL, 1);
  671.     p_pieslice(160, 110, 290, 360, 75);
  672.  
  673.     end_slice();
  674.  
  675.     printf("Elliptical pie chart, various fill patterns\n");
  676.     draw_elliptical_pie();
  677.     end_slice();
  678. }
  679.  
  680. #if defined(__HUGE__) || defined(__LARGE__) || defined(__MEDIUM__)
  681. /********************************************************************
  682.  Scale an image to best fit the aspect ratio of the printer. This only
  683.  works if the resulting xaspect >= yaspect */
  684.  
  685. static int scale_image(void far *bitmap, int xscale)
  686. {
  687. int x, y, right, bottom, old_width;
  688. int new_width, new_x;
  689. int source, dest, pixel;
  690. int far *header = bitmap;
  691. char far *data = (char far *) bitmap + 4;
  692.  
  693.     if (xscale == 0) return 0;
  694.     right = header[0];
  695.     bottom = header[1];
  696.     old_width = (right+8) / 8;
  697.     new_width = (old_width + xscale - 1)/xscale;
  698.     header[0] = new_width * 8 - 1;
  699.     for (y = 0; y <= bottom; y++) {
  700.         for (x = new_x = 0; x <= right; x += xscale, new_x++) {
  701.             source = y * old_width + x/8;
  702.             dest = y * new_width + new_x/8;
  703.             pixel = (data[source] >> (7 - (x & 7))) & 1;
  704.             data[dest] &= 0xFF7F >> (new_x & 7);
  705.             data[dest] |= (pixel << (7 - (new_x & 7)));
  706.         }
  707.     }
  708.     return 1;
  709. }
  710.  
  711.  
  712. extern int far face[];        /* Image of Anne's face, originally digitised on a Mac */
  713.  
  714.  
  715. /********************************************************************
  716.  Display Anne's face on the printer and screen, firstly unscaled (it
  717.  was saved as an image from a CGA screen via getimage), then scaled
  718.  to fit the printer's aspect ratio as near as possible. In between,
  719.  use putimage & getimage, and p_putimage & p_getimage, to swap characters
  720.  from the printer buffer to screen and vice versa. */
  721.  
  722. void image_demo(void)
  723. {
  724. char imagep[130], imageg[130];
  725. unsigned sizep;
  726. int xaspp, yaspp;
  727. int depth, width, left;
  728.  
  729.     width = face[0];
  730.     depth = face[1];
  731.     left = (MAX_WIDTH - width)/2;
  732.     p_setviewport(left, 0, left + width, depth, 1);
  733.  
  734.     sizep = p_imagesize(50, 20, 60, 30);
  735.     printf("Image size = %u bytes\n", sizep);
  736.  
  737.     start_screen_output();
  738.     p_putimage(0, 0, face, NOT_PUT);
  739.     end_slice();
  740.  
  741. #ifdef __TURBOC__
  742.     CLS;
  743.     outtextxy(0,100, "Getimage/putimage swapping screen/printer");
  744.     p_outtextxy(50, 20, "F");
  745.     outtextxy(50, 20, "G");
  746.     p_getimage(50, 20, 60, 30, imagep);
  747.     getimage(50, 20, 60, 30, imageg);
  748.     p_putimage(60, 20, imageg, COPY_PUT);
  749.     putimage(60, 20, imagep, COPY_PUT);
  750.     end_slice();
  751.     CLS;
  752.  
  753.     p_getaspectratio(&xaspp, &yaspp);
  754.     if (scale_image(face, (int)((12L * xaspp)/(yaspp * 5L)))) {
  755.         outtextxy(0,180, "Printing Scaled image");
  756.         p_outtextxy(0,150, "Scaled");
  757.         p_putimage(0, 0, (char far *)face, NOT_PUT);
  758.         end_slice();
  759.     } else {
  760.         outtextxy(0, 180, "Can't scale image -- Press a key to continue");
  761.         getch();
  762.     }
  763. #else   /* If not Turbo C */
  764.     CLS;
  765.     p_outtextxy(50, 20, "F");
  766.     p_getimage(50, 20, 60, 30, imagep);
  767.     _getimage(50, 20, 60, 30, imageg);
  768.     p_putimage(60, 20, imageg, COPY_PUT);
  769.     _putimage(60, 20, imagep, COPY_PUT);
  770.     end_slice();
  771.     CLS;
  772.  
  773.     p_getaspectratio(&xaspp, &yaspp);
  774.     if (scale_image(face, (int)((12L * xaspp)/(yaspp * 5L)))) {
  775.         p_outtextxy(0,150, "Scaled");
  776.         p_putimage(0, 0, face, NOT_PUT);
  777.         end_slice();
  778.     } else {
  779.         printf("Can't scale image -- Press a key to continue");
  780.         getch();
  781.     }
  782. #endif
  783.     stop_screen_output();
  784. }
  785.  
  786. /********************************************************************
  787.  Draw a circular pie chart on the printer, then display it on the
  788.  screen. */
  789.  
  790. void view_demo(void)
  791. {
  792.     printf("Viewing Elliptical pie chart, various fill patterns\n");
  793.     draw_elliptical_pie();
  794.     start_screen_output();
  795.     p_view();
  796. #ifdef __TURBOC__
  797.     outtextxy(0, 180, "Press a key to continue");
  798. #else
  799.     printf("Press a key to continue");
  800. #endif
  801.     getch();
  802.     stop_screen_output();
  803. }
  804.  
  805. /********************************************************************
  806.  Switch screen to graphics mode, and start echoing printer output to
  807.  the screen. */
  808.  
  809. void start_screen_output(void)
  810. {
  811. #ifdef __TURBOC__
  812. int driver = DETECT, mode;
  813.     detectgraph(&driver,&mode);
  814.     switch(driver) {
  815.     case VGA:
  816.     case EGA:
  817.         driver = CGA;
  818.     case CGA:
  819.         registerbgidriver(CGA_driver);
  820.         mode = CGAHI;
  821.         break;
  822.     case HERCMONO:
  823.         registerbgidriver(Herc_driver);
  824.         mode = HERCMONOHI;
  825.         break;
  826.     case ATT400:
  827.         mode = ATT400HI;
  828.         break;
  829.     case PC3270:
  830.         mode = PC3270HI;
  831.         break;
  832.     case MCGA:
  833.         mode = MCGAHI;
  834.         break;
  835.     }
  836.     initgraph(&driver, &mode, NULL);
  837.     if (driver < 0) {
  838.         printf("BGI Error: %s\n", grapherrormsg(graphresult()));
  839.         exit(1);
  840.     }
  841. #else
  842.     _setvideomode(_HRESBW);
  843. #endif
  844.     screen_echo = 1;
  845. }
  846.  
  847. /********************************************************************
  848.  Switch screen back to text mode, and stop echoing printer output to
  849.  the screen. */
  850.  
  851. void stop_screen_output(void)
  852. {
  853. #ifdef __TURBOC__
  854.     closegraph();
  855. #else
  856.     _setvideomode(_DEFAULTMODE);
  857. #endif
  858.     screen_echo = 0;
  859. }
  860.  
  861. /********************************************************************
  862.  Output pixels to screen if flag set -- called from p_putpixel()   */
  863.  
  864. void far _p_putpixel_screen(int x, int y, int colour)
  865. {
  866.     if (screen_echo)
  867. #ifdef __TURBOC__
  868.         putpixel(x, y, colour);
  869. #else
  870.         { _setcolor(colour); _setpixel(x, y); }
  871. #endif
  872.  
  873. }
  874. #endif
  875.